<template>
  <router-view></router-view>
</template>

<script setup lang="ts">
import {onBeforeRouteUpdate} from "vue-router";
const store = useStore()
const router = useRouter()
const route = useRoute()

const validateMallConfig = (path: string) => {
  const {mallConfig} = store.state.pointsMall
  const {id: mallId} = mallConfig

  if (path !== '/mall/manage/list' && !mallId) {
    router.replace('/mall/manage/list')
    return false
  }

  return true
}

onBeforeRouteUpdate((to, from) => {
  return validateMallConfig(to.path)
})

onBeforeMount(() => {
  validateMallConfig(route.path)
})
</script>
